package com.example.smartgreenhouse.aliyun_bailian;

import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.example.smartgreenhouse.annotation.JwtToken;
import com.example.smartgreenhouse.annotation.Limit;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("gsas/api/v1/baiLian")
public class BaiLianController {

    @Autowired
    private BaiLianService baiLianService;
    @PostMapping("chatWithBaiLian")
    @JwtToken
    public ResponseEntity<Map<String,Object>> callBaiLian(@RequestBody BaiLianRequest request) throws NoApiKeyException, InputRequiredException {
        String res = baiLianService.callBaiLianApi(request.getInput());
        Map<String,Object> response = new HashMap<>();
        response.put("code",200);
        response.put("message","success");
        response.put("data",res);
        return ResponseEntity.ok(response);
    }
    @Data
    public static class BaiLianRequest{
        String input;
    }
}
